package com.cssl.controller;

import cn.hutool.core.util.ObjectUtil;
import com.cssl.domain.dto.DtskeywordDto;
import com.cssl.service.Dtskeywordservice;
import com.cssl.util.InfoCode;
import com.cssl.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/keyword")
public class DtskeywordController {
    @Autowired
    Dtskeywordservice dtskeywordservice;
    @PostMapping("/list")
    Result dtskeywordlist(@RequestBody DtskeywordDto dtskeywordDto){
        Map keywordlist=dtskeywordservice.findPagekeyword(dtskeywordDto);
        if (keywordlist==null|| ObjectUtil.isEmpty(keywordlist.get("list"))) {
            return Result.result(InfoCode.QUERY_EMPTY, InfoCode.MESSAGE_QUERY_EMPTY, null, System.currentTimeMillis());
        }
        System.out.println("订单数据"+dtskeywordDto.getLimit()+dtskeywordDto.getPage());
        System.out.println("订单状态"+dtskeywordDto.getKeyword());
        return Result.result(InfoCode.OK,InfoCode.MESSAGE_OK,keywordlist,System.currentTimeMillis());
    }
    @DeleteMapping("/delete")
    Result keyworddelete(@RequestParam("ids") String ids){
        boolean kydelete=dtskeywordservice.keyworddelete(ids);
        System.out.println("id:"+ids);
        if(kydelete){
            return Result.result(InfoCode.OK, "删除成功", null, System.currentTimeMillis());
        }else {
            return Result.result(InfoCode.FAILED, "删除失败", null, System.currentTimeMillis());
        }
    }

    @PostMapping("/keywordupdate")
    Result keywordupdate(@RequestBody Map keywordupdate){
        int update=dtskeywordservice.updatekeyword(keywordupdate);
        System.out.println("信息"+keywordupdate.size());
        return Result.result(InfoCode.OK,InfoCode.MESSAGE_OK,update,System.currentTimeMillis());
    }

    @PostMapping("/addkeyword")
    Result addkeyword(@RequestBody Map addkeyword){
        int keywordadd=dtskeywordservice.addkeyword(addkeyword);
        System.out.println("信息"+addkeyword.size());
        return Result.result(InfoCode.OK,InfoCode.MESSAGE_OK,keywordadd,System.currentTimeMillis());
    }
}
